package com.kingdee.shr.recuritment.web.handler.interview;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.ui.ModelMap;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.recuritment.InterviewerManagementFactory;
import com.kingdee.shr.recuritment.InterviewerManagementInfo;

public class InterviewerManagementEditHandlerEx extends
		InterviewerManagementEditHandler {
	 private static Logger logger = Logger.getLogger("com.kingdee.shr.recuritment.web.handler.InterviewerManagementEditHandlerEx");

	@Override
	public void editInterviewerAction(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap)
			throws SHRWebException {
		String interviewerManagementId = request.getParameter("interviewerManagementId");
		String interviewStageIds = request.getParameter("InterviewStageIds");
		String interviewStageNames = request.getParameter("InterviewStageNames");
		try {
			InterviewerManagementInfo info = new InterviewerManagementInfo();
			info.put("InterviewStageIds", interviewStageIds);
			info.put("InterviewStageNames", interviewStageNames);
			info.setId(BOSUuid.read(interviewerManagementId));
			SelectorItemCollection sic = new SelectorItemCollection();
			sic.add("id");
			sic.add("InterviewStageIds");
			sic.add("InterviewStageNames");
			InterviewerManagementFactory.getRemoteInstance().updatePartial(info, sic);
		} catch (EASBizException e) {
			e.printStackTrace();
		} catch (BOSException e) {
			e.printStackTrace();
		}
		super.editInterviewerAction(request, response, modelMap);
	}

//	public void addInterviewersAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
//		    throws SHRWebException{
//		Context ctx = SHRContext.getInstance().getContext();
//		UserInfo userInfo = ContextUtil.getCurrentUserInfo(ctx);
//		Map map = new HashMap();
//		InterviewRangeInfo interviewRange = new InterviewRangeInfo();
//		InterviewerManagementInfo interviewerManagement = new InterviewerManagementInfo();
//		String state = "error";
//		try {
//			IInterviewerManagement iInterviewerManagement = InterviewerManagementFactory.getRemoteInstance();
//			IInterviewRange iInterviewRange = InterviewRangeFactory.getRemoteInstance();
//			String Interviewers = request.getParameter("Interviewers");
//			String InterviewRanges = request.getParameter("interviewRanges");
//			InterviewRange[] interviewRanges = (InterviewRange[])(InterviewRange[])JSONUtils.convertJsonToObject(InterviewRanges, com.kingdee.shr.recuritment.util.vo.InterviewRange.class);
//			InterviewerManagement[] interviewerManagements = (InterviewerManagement[])(InterviewerManagement[])JSONUtils.convertJsonToObject(Interviewers, com.kingdee.shr.recuritment.util.vo.InterviewerManagement.class);
//
//			for (int i = 0; i < interviewerManagements.length; ++i) {
//				interviewerManagement = interviewerManagements[i].convert();
//			    interviewerManagement.setCreator(userInfo);
//			    interviewerManagement.setCreateTime(new Timestamp(new Date().getTime()));
//
//			    interviewerManagement.setJoinDate(RecBaseUtils.getNowDate());
//			    iInterviewerManagement.save(interviewerManagement);
//			    AdminOrgUnitInfo department = interviewerManagement.getDepartment();
//			    boolean repeat = false;
//			    for (int j = 0; j < interviewRanges.length; ++j) {
//			    	interviewRange = interviewRanges[j].convert();
//			    	interviewRange.setInterviewerManagement(interviewerManagement);
//			    	iInterviewRange.save(interviewRange);
//			    	if (department.equals(interviewRange.getAbleDepartNames()))
//			        repeat = true;
//			    }
//			    if (!(repeat)) {
//			    	interviewRange = new InterviewRangeInfo();
//			    	interviewRange.setIncludeSub(YesOrNoEnum.YES);
//			    	interviewRange.setUseRange(InterviewerUseRangeEnum.ADMINORGUNIT);
//			    	interviewRange.setAbleDepartNames(interviewerManagement.getDepartment());
//			    	interviewRange.setInterviewerManagement(interviewerManagement);
//			    	iInterviewRange.save(interviewRange);
//			    }
//			    iInterviewerManagement.updateInterviewerManagementDatas(interviewerManagement.getId().toString());
//		  }
//		  state = "ok";
//		} catch (EASBizException e) {
//		  logger.error(e.getMessage(), e);
//		  throw new ShrWebBizException(e.getMessage(), e);
//		} catch (BOSException e) {
//		  logger.error(e.getMessage(), e);
//		  throw new SHRWebException(e.getMessage(), e);
//		}
//		map.put("state", state);
//	    JSONUtils.writeJson(response, map);
//	}
}
